define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        //积分商品
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'goods/index' + location.search,
                    add_url: 'goods/add',
                    edit_url: 'goods/edit',
                    del_url: 'goods/del',
                    multi_url: 'goods/multi',
                    import_url: 'goods/import',
                    table: 'goods',
                }
            });
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'goodscate.title', title: __('分类名称'), operate: 'LIKE'},
                        {field: 'title', title: __('名称'), operate: 'LIKE'},
                        {field: 'score', title: __('现价积分/折扣价'), operate: 'LIKE'},
                        {field: 'old_score', title: __('原价积分/原价'), operate: 'LIKE'},
                        {
                            field: 'image',
                            title: __('Image'),
                            operate: false,
                            events: Table.api.events.image,
                            formatter: Table.api.formatter.image
                        },
                        {field: 'address', title: __('发货地'), operate: 'LIKE'},
                        {field: 'factory', title: __('厂家'), operate: 'LIKE'},
                        {field: 'cost_price', title: __('成本'), operate: 'LIKE'},
                        {
                            field: 'is_postage',
                            title: __('是否包邮'),
                            searchList: {"1": __('包邮'), "-1": __('不包邮')},
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'is_top',
                            title: __('是否推荐'),
                            searchList: {"1": __('推荐'), "-1": __('不推荐')},
                            formatter: Table.api.formatter.normal
                        },
                        // {field: 'weigh', title: __('Weigh'), operate: false},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        //拼团商品
        pin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    pin_url: 'goods/pin' + location.search,
                    add_url: 'goods/add',
                    edit_url: 'goods/edit',
                    del_url: 'goods/del',
                    multi_url: 'goods/multi',
                    import_url: 'goods/import',
                    table: 'goods',
                }
            });
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.put_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'goodscate.title', title: __('Goodscate.title'), operate: 'LIKE'},
                        {field: 'procurement', title: __('Procurement'), operate: 'LIKE'},
                        {field: 'cost_price', title: __('Cost_price'), operate: 'LIKE'},
                        {field: 'score', title: __('Score'), operate: 'LIKE'},
                        {field: 'old_score', title: __('Old_score'), operate: 'LIKE'},
                        {field: 'sell', title: __('Sell')},
                        {field: 'stock', title: __('Stock')},
                        // {field: 'out_time', title: __('Out_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {"1": __('Status 1'), "-1": __('Status -1')},
                            formatter: Table.api.formatter.status
                        },
                        {field: 'service', title: __('Service'), operate: 'LIKE'},
                        {field: 'price', title: __('Price'), operate: 'BETWEEN'},
                        {field: 'postage', title: __('Postage'), operate: 'BETWEEN'},
                        {
                            field: 'is_postage',
                            title: __('Is_postage'),
                            searchList: {"1": __('Is_postage 1'), "-1": __('Is_postage -1')},
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'is_top',
                            title: __('Is_top'),
                            searchList: {"1": __('Is_top 1'), "-1": __('Is_top -1')},
                            formatter: Table.api.formatter.normal
                        },
                        // {field: 'weigh', title: __('Weigh'), operate: false},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        //财务支出
        procurement: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    procurement_url: 'goods/procurement' + location.search,
                    add_url: 'goods/add',
                    edit_url: 'goods/edit',
                    del_url: 'goods/del',
                    multi_url: 'goods/multi',
                    import_url: 'goods/import',
                    table: 'goods',
                }
            });
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.procurement_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'goodscate.title', title: __('Goodscate.title'), operate: 'LIKE'},
                        {field: 'cost_price', title: __('Cost_price'), operate: 'LIKE'},
                        {field: 'today_count', title: __('Today_count'), operate: 'LIKE'},
                        {field: 'today_money', title: __('Today_money'), operate: 'LIKE'},
                        // {field: 'all_money', title: __('All_money'), operate: 'LIKE'},

                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});